﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WanFang.IRepositories;

namespace WanFang.Test
{
    public class DynamicFieldService : IDynamicFieldService, IApplicationService
    {
        private readonly IDynamicFieldRepository _repository;
        public DynamicFieldService(IDynamicFieldRepository repository)
        {
            _repository = repository;
        }
        public async Task CreateField(int materialId, string[] fname, string[] ftype)
        {
            List<JianCeTemplate> lst = new List<JianCeTemplate>();
            for (int i = 0; i < fname.Length; i++) {
                if(string.IsNullOrEmpty(fname[i]) || string.IsNullOrEmpty(ftype[i]))
                {
                    continue;
                }
                lst.Add(new JianCeTemplate() { Material_Id =materialId, Name =fname[i],FieldCategory=ftype[i] });
            }
            await _repository.CreateField(lst);
        }
        public JianCeTemplate Get(int id)
        {
            return _repository.Get(id);
        }
        public IList<JianCeTemplate> GetList()
        {
           return _repository.GetAll().ToList();
        }
        public IList<JianCeTemplate> GetList(int materialId)
        {
            return _repository.GetAll().Where(t => t.Material_Id == materialId).ToList();
        }
        public void Add(JianCeTemplate entity)
        {
            _repository.Insert(entity);
        }
        public void Update(JianCeTemplate entity)
        {
            _repository.Update(entity);
        }
        public void Delete(JianCeTemplate entity)
        {
            _repository.Delete(entity);
        }
        public void Delete(int id)
        {
            _repository.Delete(id);
        }
        public void AddJianCeItem(int jianceId, Dictionary<string, string> dic)
        {
            _repository.AddJianCeItem(jianceId, dic);
        }
    }
}
